home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Tele / Pete Johnson / Mehit 3.0.b15<source> Folder / DebugDialog.p < prev    next >
Encoding:
Text File  |  1991-07-10  |  6.6 KB  |  265 lines  |  [TEXT/PJMM]

  1. unit Debug;
  2.  
  3. {Written by Pete Johnson 6/23/91}
  4.  
  5. {Creates and updates a debug status window using no resources. Use debugStr1,  debugStr2 and debugStr3     }
  6. {for status messages. Also shows free memory, last memory error and resource error codes.                        }
  7.  
  8. {Use:}
  9. {Call SetupDebug, assign strings to the three debugStr variables and call Update Debug. When finished, call        }
  10. {KillDebug. Other handy calls:                                                                                                                        }
  11. {    SetDebugStrings(str1,str2,str3) lets you set all three debug strings in one call                                            }
  12. {    ShowErrStr returns a decoded error or a string of the error number                                                            }
  13.  
  14. interface
  15.  
  16. var
  17.     debugWindow: WindowPtr;
  18.     debugStr1, debugStr2, debugStr3: str255;
  19.     debugCounter: longint;
  20.  
  21. procedure SetupDebug;
  22.  
  23. procedure SetDebugStrings (string1, string2, string3: str255);
  24.  
  25. function ShowErrStr (theErr: integer): str255;
  26.  
  27. procedure UpdateDebug;
  28.  
  29. procedure IncrementDebug;
  30.  
  31. procedure WaitDebug;
  32.  
  33. procedure CloseDebug;
  34.  
  35. implementation
  36.  
  37. { ================================  RedrawRect  ================================ }
  38.  
  39. procedure RedrawRect (theRect: rect; L, T, R, B: integer);
  40.  
  41.     begin
  42.         SetRect(theRect, L, T, R, B);    {left, top, right, bottom}
  43.         FrameRect(theRect);
  44.         InsetRect(theRect, 1, 1);
  45.         EraseRect(theRect)
  46.     end;
  47.  
  48. { ================================  ShowErrString  ================================ }
  49.  
  50. function ShowErrStr;{(theErr:integer): str255}
  51.     {returns decoded error code or a string of the error number}
  52.  
  53.     begin
  54.         case theErr of
  55.             tmwdoErr: 
  56.                 ShowErrStr := 'too many wdir open';
  57.             dirNFErr: 
  58.                 ShowErrStr := 'dir not found';
  59.             fsRnErr: 
  60.                 ShowErrStr := 'can''t rename file';
  61.             permErr: 
  62.                 ShowErrStr := 'can''t write locked file';
  63.             volOffLinErr: 
  64.                 ShowErrStr := 'vol not on line';
  65.             rfNumErr: 
  66.                 ShowErrStr := 'no such path';
  67.             paramErr: 
  68.                 ShowErrStr := 'no default vol';
  69.             vLckdErr: 
  70.                 ShowErrStr := 'file locked';
  71.             fLckdErr, wPrErr: 
  72.                 ShowErrStr := 'volume locked';
  73.             fnfErr: 
  74.                 ShowErrStr := 'file not found';
  75.             tmfoErr: 
  76.                 ShowErrStr := 'too many files open';
  77.             posErr: 
  78.                 ShowErrStr := 'position error';
  79.             eofErr: 
  80.                 ShowErrStr := 'hit eof on read';
  81.             fnOpnErr: 
  82.                 ShowErrStr := 'file not open';
  83.             bdNamErr: 
  84.                 ShowErrStr := 'bad file/vol name';
  85.             ioErr: 
  86.                 ShowErrStr := 'i/o error';
  87.             nsvErr: 
  88.                 ShowErrStr := 'no such vol';
  89.             dskFulErr: 
  90.                 ShowErrStr := 'disk full';
  91.             dirFulErr: 
  92.                 ShowErrStr := 'directory full';
  93.             memLockedErr: 
  94.                 ShowErrStr := 'locked block';
  95.             nilHandleErr: 
  96.                 ShowErrStr := 'nil master pointer';
  97.             memFullErr: 
  98.                 ShowErrStr := 'no room in heap';
  99.             noErr: 
  100.                 ShowErrStr := 'no error';
  101.             otherwise
  102.                 ShowErrStr := stringOf(theErr : 1)
  103.         end    {case}
  104.     end;
  105.  
  106. { ================================  SetDebugStrings  ================================ }
  107.  
  108. procedure SetDebugStrings;{(string1, string2, string3: str255)}
  109.  
  110.     begin
  111.         debugStr1 := string1;
  112.         debugStr2 := string2;
  113.         debugStr3 := string3
  114.     end;
  115.  
  116. { ================================  KillDebug  ================================ }
  117.  
  118. procedure CloseDebug;
  119.  
  120.     begin
  121.         if debugWindow <> nil then
  122.             begin
  123.                 DisposeWindow(debugWindow);
  124.                 debugWindow := nil
  125.             end;
  126.     end;
  127.  
  128. { ================================  UpdateDebug  ================================ }
  129.  
  130. procedure UpdateDebug;
  131.  
  132.     var
  133.         rect1, rect2, rect3, rect4, rect5, rect6: rect;
  134.         freeBytes: longint;
  135.         oldPort: grafPtr;
  136.  
  137.     begin
  138.         if debugWindow <> nil then
  139.             begin
  140.                 GetPort(oldPort);
  141.                 SetPort(debugWindow);
  142.                 textFont(Geneva);
  143.                 textSize(9);
  144.                 ForeColor(redColor);
  145.                 RedrawRect(rect1, 5, 4, 180, 18);            {left, top, right, bottom}
  146.                 RedrawRect(rect2, 5, 20, 180, 34);            {left, top, right, bottom}
  147.                 RedrawRect(rect3, 5, 36, 180, 50);            {left, top, right, bottom}
  148.                 RedrawRect(rect4, 5, 52, 62, 66);            {left, top, right, bottom}
  149.                 RedrawRect(rect5, 64, 52, 121, 66);        {left, top, right, bottom}
  150.                 RedrawRect(rect6, 123, 52, 180, 66);        {left, top, right, bottom}
  151.                 MoveTo(9, 14);
  152.                 DrawString(debugStr1);
  153.                 MoveTo(9, 30);
  154.                 DrawString(debugStr2);
  155.                 MoveTo(9, 46);
  156.                 DrawString(debugStr3);
  157.                 freeBytes := FreeMem;
  158.                 MoveTo(9, 62);
  159.                 DrawString(concat(stringOf(freeBytes div 1024 : 1), 'K'));
  160.                 MoveTo(68, 62);
  161.                 DrawString(concat('M: ', stringOf(MemError : 1)));
  162.                 MoveTo(127, 62);
  163.                 DrawString(concat('R: ', stringOf(ResError : 1)));
  164.                 SetPort(oldPort)
  165.             end
  166.     end;
  167.  
  168. { ================================  WaitDebug  ================================ }
  169.  
  170. procedure WaitDebug;
  171.  
  172.     const
  173.         sleep = 10;
  174.  
  175.     var
  176.         mouseLoc: point;
  177.         clickInWindow: boolean;
  178.         theEvent: EventRecord;
  179.         whichWindow: WindowPtr;
  180.         result: integer;
  181.  
  182.     begin
  183.         if debugWindow <> nil then
  184.             begin
  185.                 clickInWindow := false;
  186.                 UpdateDebug;
  187.                 repeat
  188.                     if WaitNextEvent(mDownMask, theEvent, sleep, nil) then
  189.                         begin
  190.                             result := FindWindow(theEvent.where, whichWindow);
  191.                             if whichWindow = debugWindow then
  192.                                 begin
  193.                                     case theEvent.what of
  194.                                         mouseDown: 
  195.                                             case result of
  196.                                                 activateEvt: 
  197.                                                     begin
  198.                                                         SelectWindow(whichWindow);
  199.                                                         UpdateDebug;
  200.                                                     end;
  201.                                                 inContent: 
  202.                                                     clickInWindow := true;
  203.                                                 inDrag: 
  204.                                                     begin
  205.                                                         DragWindow(whichWindow, theEvent.where, screenbits.bounds);
  206.                                                         UpdateDebug;
  207.                                                     end;
  208.                                                 otherwise
  209.                                                     ;
  210.                                             end;
  211.                                         otherwise
  212.                                             ;
  213.                                     end
  214.                                 end
  215.                         end;
  216.                 until clickInWindow;
  217.                 if button then
  218.                     repeat
  219.                     until not button
  220.             end
  221.     end;
  222.  
  223. { ================================  IncrementDebug  ================================ }
  224.  
  225. procedure IncrementDebug;
  226.  
  227.     begin
  228.         if debugWindow <> nil then
  229.             begin
  230.                 debugCounter := succ(debugCounter);
  231.                 debugStr3 := concat('Checkpoint #', stringOf(debugCounter : 1), '   Click to continue …');
  232.                 WaitDebug
  233.             end
  234.     end;
  235.  
  236. { ================================   SetUp   ================================ }
  237.  
  238. procedure SetupDebug;
  239.  
  240.     const
  241.         debugHeight = 69;        {height of debug window}
  242.         debugWidth = 184;    {width of debug window}
  243.  
  244.     var
  245.         wRect: rect;
  246.         title: str255;
  247.         itemList: handle;
  248.         itemHit: integer;
  249.         oldPort: GrafPtr;
  250.         debugV, debugH: integer;
  251.  
  252.     begin
  253.         GetPort(oldPort);
  254.         SetDebugStrings('', '', '');
  255.         debugCounter := 0;
  256. {                        next few lines put window at bottom left of screen            }
  257.         debugV := Screenbits.bounds.bottom - debugHeight;
  258.         debugH := Screenbits.bounds.right - debugWidth;
  259.         SetRect(wRect, debugH, debugV, debugH + debugWidth, debugV + debugHeight);    {left, top, right, bottom}
  260.         title := 'Debug';
  261.         debugWindow := NewWindow(nil, wRect, title, true, NoGrowDocProc, Pointer(-1), false, longint('Pete'));
  262.         ShowWindow(debugWindow);
  263.         SetPort(oldPort)
  264.     end;
  265. end.